package com.mouse.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mouse.entity.Mouse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mouse.entity.Phenotype;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author godson
 * @since 2022-08-07
 */
public interface MouseMapper extends BaseMapper<Mouse> {
    @Select("Select DISTINCT m.* FROM (SELECT gcom.* FROM gene_category gca LEFT JOIN genecategory_genecomposition gg ON gca.gid=gg.gid LEFT JOIN gene_composition gcom ON gg.gcid=gcom.gcid WHERE gca.gid=#{gid}) gcom_result\n" +
            "LEFT JOIN mouse m ON gcom_result.gcid = m.gcid ")
    List<Mouse> getMouseByGid(@Param("gid") Long gid);


    @Select("SELECT m.* FROM gene_composition gcom LEFT JOIN mouse m ON gcom.gcid=m.gcid WHERE gcom.gcid=#{gcid}")
    List<Mouse> getMouseByGcID(@Param("gcid") Long gcid);

    /***
     * 3.2.1.2
     * @param did
     * @return
     */
    @Select("SELECT m.* FROM\n" +
            "(SELECT gc.* FROM (SELECT gcda.gcid FROM  double_alleles da LEFT JOIN gene_composition_double_alleles gcda ON da.did=gcda.did WHERE da.did=#{did}) res LEFT JOIN gene_composition gc on res.gcid=gc.gcid) gc_res\n" +
            "LEFT JOIN mouse m ON m.gcid=gc_res.gcid ")
    List<Mouse> getMouseByDid(@Param("did") Long did);



    @Select("SELECT DISTINCT m.* FROM gene_allele ga LEFT JOIN double_alleles_gene_allele daga ON ga.aid=daga.aid LEFT JOIN double_alleles da ON daga.did= da.did \n" +
            "LEFT JOIN gene_composition_double_alleles gcda ON gcda.did=da.did LEFT JOIN gene_composition gcom on gcda.gcid=gcom.gcid\n" +
            "LEFT JOIN mouse m ON m.gcid=gcom.gcid \n" +
            "WHERE daga.aid=#{aid}")
    List<Mouse> getMouseByAid(@Param("aid") Long aid);

}
